//
//  PersonViewControler.m
//  Cabinet
//
//  Created by Florent Montsegur on 01/05/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PersonViewControler.h"


@implementation PersonViewControler

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView{
    return [self count];
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex{
    
    if( rowIndex >= [self count])
        return @"";
    
    Person *p = [mPersons objectAtIndex:rowIndex];
    
    if( [[aTableColumn identifier] caseInsensitiveCompare:@"nom"] == NSOrderedSame )
        return [p Nom];
    
    if( [[aTableColumn identifier] caseInsensitiveCompare:@"prenom"] == NSOrderedSame )
        return [p Prenom];
        
    return @"";
}

- (NSInteger) count{
    return [mPersons count];
}

- (Person*)getPersonAtIndex:(NSInteger)aRowIndex
{
    if(aRowIndex<0) 
        return nil;
    
    if(aRowIndex>=[self count]) 
        return nil;
    
    return [mPersons objectAtIndex:aRowIndex];
}

- (void) setPersons:(NSArray*)aPersonList
{
    mPersons = aPersonList;
}


@end
